package web.servlet;

import com.alibaba.fastjson.JSON;
import domain.Product;
import jakarta.servlet.ServletException;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import service.CatelogService;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

public class ProductAutoCompleteServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String keyword=req.getParameter("keyword");
        CatelogService service=new CatelogService();
        List<Product> productList=service.searchProductList(keyword);

        String result= JSON.toJSONString(productList);

        System.out.println("success");
        resp.setContentType("text/json");
        PrintWriter out=resp.getWriter();
        out.println(result);
    }
}
